package com.hdoit.ares.logical.tp.dao.impl;

import java.util.List;

import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import com.hdoit.ares.logical.tp.dao.IFanhuaInsuPlaceDao;
import com.hdoit.ares.logical.tp.model.FanhuaInsuPlace;
import com.hdoit.ares.logical.viewmodel.tp.FanhuaInsuPlaceSearch;
import com.tennetcn.common.dao.base.IFinderExpression;
import com.tennetcn.common.dao.base.impl.SuperDao;
import com.tennetcn.common.enums.OrderEnum;
import com.tennetcn.common.utils.FinderExpressionFactory;
/**
 * @author      caochengmeng
 * @email       
 * @createtime  2018年01月26日 20:32:09
 * @comment
 */
@Component
public class FanhuaInsuPlaceDaoImpl extends SuperDao<FanhuaInsuPlace> implements IFanhuaInsuPlaceDao{
	
	@Override
	public List<FanhuaInsuPlace> queryList(FanhuaInsuPlaceSearch search) {
		IFinderExpression finderExpression=FinderExpressionFactory.createExpression();
		finderExpression.select("a.*,b.paramText as 'parentParamText'")
						.from(FanhuaInsuPlace.class,"a")
						.leftJoin(FanhuaInsuPlace.class,"b").on("a.parentId", "b.id")
						.setMainTableAlias("a")
						.addOrder("a.sortCode", OrderEnum.asc);

			appendFinder(finderExpression,search);	
		return queryList(finderExpression,search);
	}
	private void appendFinder(IFinderExpression finderExpression,FanhuaInsuPlaceSearch search){
		if(!StringUtils.isEmpty(search.getParamName())){
			finderExpression.andMainTableWhere("paramName=#{paramName}")
							.setParam("paramName", search.getParamName());
		}
		if(!StringUtils.isEmpty(search.getParentId())){
			finderExpression.andMainTableWhere("parentId=#{parentId}")
							.setParam("parentId", search.getParentId());
		}
		if(!StringUtils.isEmpty(search.getParamValue())){
			finderExpression.andMainTableWhere("paramValue=#{paramValue}")
							.setParam("paramValue", search.getParamValue());
		}
	}
}